package com.chandra.pos.order.repository;

import com.chandra.pos.order.dao.entity.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Customer: T4671
 * Date: 10/1/13
 * Time: 4:34 PM
 * To change this template use File | Settings | File Templates.
 *
 * http://spring.io/blog/2011/02/10/getting-started-with-spring-data-jpa/
 */

@Transactional(readOnly = true)
public interface OrderRepository extends JpaRepository<Order, Long>,OrderRepositoryCustom{

   // public List<Order> findByNameLike(String name);

    @Query("SELECT ghawhs FROM Order ghawhs where ghawhs.customerId= :customerId ")
    public List<Order> getOrdersByCustomerID(@Param("customerId") Long customerId);

    @Modifying
    @Query("update Order u set u.status = ?1 where u.id = ?2")
    int updateOrderStatus(int status, Long orderId);

    @Modifying
    @Query("update Order u set u.shippingStatus = ?1 where u.id = ?2")
    int updateShippingStatus(int shippingStatus, Long orderId);


    @Modifying
    @Query("update Order u set u.orderDate = ?1 where u.id = ?2")
    int updateOrderDate(Date orderDate, Long orderId);

    @Modifying
    @Query("update Order u set u.shippingDate = ?1 where u.id = ?2")
    int updateShippingDate(Date shippingDate, Long orderId);

    @Modifying
    @Query("update Order u set u.dueDate = ?1 where u.id = ?2")
    int updateDueDate(Date dueDate, Long orderId);

    @Modifying
    @Query("update Order u set u.note = ?1 where u.id = ?2")
    int updateOrderNote(String note, Long orderId);




}
